﻿using System;
using System.Collections.Generic;
using System.IO;
using Windows.UI.Xaml.Media.Imaging;
using System.Linq;
using System.Windows.Input;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Input;
using Windows.UI.Core;
using System.Threading;
using System.Collections.Concurrent;

namespace RoboRun
{
    class CountdownAnimation
    {
        public static async void countdownAnimation(Image Countdown, float height, float width, float offset)
        {
            Countdown.Height = height;
            Countdown.Width = height - 70;
            Countdown.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/Countdown/3.png", UriKind.Absolute
                   ));
            Countdown.Margin = new Thickness(width / 2 - 100 * width / 1920, height / 2 - 400 * height / 1080, 0, offset);
            Countdown.Opacity = 0;
            int i = (int)height;
            double j = 0;
            while (i > (224 * height / 1080) || j < 1)
            {
                Countdown.Height = i;
                Countdown.Width = i - 70;
                Countdown.Opacity = j;
                i -= 14;
                j += 0.06;
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(5));
            }
            await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(200));
            ///
            Countdown.Source = null;
            Countdown.Height = height;
            Countdown.Width = height - 64;
            Countdown.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/Countdown/2.png", UriKind.Absolute
                   ));
            Countdown.Opacity = 0;
            i = (int)height;
            j = 0;
            while (i > (223 * height / 1080) || j < 1)
            {
                Countdown.Height = i;
                Countdown.Width = i - 70;
                Countdown.Opacity = j;
                i -= 14;
                j += 0.06;
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(5));
            }
            await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(200));
            ///
            Countdown.Source = null;
            Countdown.Height = height;
            Countdown.Width = height - 178;
            Countdown.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/Countdown/1.png", UriKind.Absolute
                   ));
            Countdown.Opacity = 0;
            i = (int)height;
            j = 0;
            while (i > (200 * height / 1080) || j < 1)
            {
                Countdown.Height = i;
                Countdown.Width = i - 70;
                Countdown.Opacity = j;
                i -= 14;
                j += 0.06;
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(5));
            }
            await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(200));
            ///
            Countdown.Source = null;
            Countdown.Height = height;
            Countdown.Width = height + 239;
            Countdown.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/Countdown/GO.png", UriKind.Absolute
                   ));
            Countdown.Opacity = 0;
            i = (int)width;
            j = 0;
            while (i > (552 * width / 1080) || j < 1)
            {
                Countdown.Height = i;
                Countdown.Width = i - 70;
                Countdown.Opacity = j;
                i -= 14;
                j += 0.06;
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(5));
            }
            await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(200));
            while (j >= 0)
            {
                Countdown.Opacity = j;
                j -= 0.07;
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(5));
            }
            Countdown.Source = null;
        }
    }
}
